package cqrtplm.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ty.basic.response.ResponseResult;
import cqrtplm.constant.RouteConstant;
import cqrtplm.entity.RtCertFiledRatoModelsDO;
import cqrtplm.service.RtCertFiledRatoModelsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 机型认证清单控制器
 */
@RestController
@Api(tags = "认证-机型认证清单")
@RequestMapping("/rest"+RouteConstant.RATO + "cert/ratomodels/" + "v1")
public class RtCertFiledRatoModelsController {

    @Autowired
    private RtCertFiledRatoModelsService rtCertFiledRatoModelsService;

    /**
     * 查询机型认证清单列表
     */
    @PostMapping("/list")
    @ApiOperation(value = "list", notes = "获取机型认证清单列表")
    public ResponseResult list(@RequestBody RtCertFiledRatoModelsDO rtCertFiledRatoModels) {
        List<RtCertFiledRatoModelsDO> list = rtCertFiledRatoModelsService.selectRtCertFiledRatoModelsList(rtCertFiledRatoModels);
        return ResponseResult.success(list);
    }

    /**
     * 分页查询机型认证清单列表
     */
    @PostMapping("/pagelist")
    @ApiOperation(value = "pagelist", notes = "分页获取机型认证清单列表")
    public ResponseResult<PageInfo<RtCertFiledRatoModelsDO>> pagelist(
            @RequestBody RtCertFiledRatoModelsDO rtCertFiledRatoModels,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "100") int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<RtCertFiledRatoModelsDO> list = rtCertFiledRatoModelsService.selectRtCertFiledRatoModelsList(rtCertFiledRatoModels);
        PageInfo<RtCertFiledRatoModelsDO> pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }

    /**
     * 导出机型认证清单列表
     */
    @PostMapping("/export")
    @ApiOperation(value = "export", notes = "导出机型认证清单列表")
    public void export(HttpServletResponse response, RtCertFiledRatoModelsDO rtCertFiledRatoModels) {
        List<RtCertFiledRatoModelsDO> list = rtCertFiledRatoModelsService.selectRtCertFiledRatoModelsList(rtCertFiledRatoModels);
        // ExcelUtil.listToExcel(list, RtCertFiledRatoModelsDO.class, wwb, "机型认证清单数据");
    }

    /**
     * 获取机型认证清单详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "getInfo", notes = "获取机型认证清单详情")
    public ResponseResult getInfo(@PathVariable("id") String id) {
        return ResponseResult.success(rtCertFiledRatoModelsService.selectRtCertFiledRatoModelsById(id));
    }

    /**
     * 新增机型认证清单
     */
    @PostMapping("/add")
    @ApiOperation(value = "add", notes = "新增机型认证清单")
    public ResponseResult add(@RequestBody RtCertFiledRatoModelsDO rtCertFiledRatoModels) {
        return ResponseResult.success(rtCertFiledRatoModelsService.insertRtCertFiledRatoModels(rtCertFiledRatoModels));
    }

    /**
     * 修改机型认证清单
     */
    @PostMapping("/edit")
    @ApiOperation(value = "edit", notes = "修改机型认证清单")
    public ResponseResult edit(@RequestBody RtCertFiledRatoModelsDO rtCertFiledRatoModels) {
        return ResponseResult.success(rtCertFiledRatoModelsService.updateRtCertFiledRatoModels(rtCertFiledRatoModels));
    }

    /**
     * 删除机型认证清单
     */
    @DeleteMapping("/del")
    @ApiOperation(value = "delete", notes = "删除机型认证清单")
    public ResponseResult remove(@RequestBody List<String> ids) {
        return ResponseResult.success(rtCertFiledRatoModelsService.deleteRtCertFiledRatoModelsByIds(ids));
    }

    /**
     * 根据开发令查询机型认证清单
     */
    @GetMapping("/devcode")
    @ApiOperation(value = "getByDevCode", notes = "根据开发令查询机型认证清单")
    public ResponseResult getByDevCode(@RequestParam("filedId") String filedId,  @RequestParam("devCode") String devCode) {
        return ResponseResult.success(rtCertFiledRatoModelsService.selectRtCertFiledRatoModelsByDevCode(filedId,devCode));
    }
}